﻿
angular.module('SLG')
  .controller("citysController", function ($scope, $state, $rootScope, $http) {
      $scope.citys = [];
      $scope.showHero = false;

      function getCitys() {
          var url = "../../Api.ashx?sys:sno=City&sys:act=GetList";

          $http.get(url).success(function (data) {
              if (data.IsSuccess) {
                  var _citys = data.Data.Items;
                  for (var i = 0; i < _citys.length; i++) {
                      _citys[i].src = "res/building/" + _citys[i].Level + ".png";
                  }
                  $scope.citys = _citys;
              }
              
          })
      }

      $scope.showHeroByCity = function (item) {
          $scope.showHero = true;
          $state.go("citys.hero", { cityId: item.Id });
      }

      getCitys();
  })

.controller("heroController", function ($scope, $state, $rootScope, $http, $stateParams) {
    var cityId = $stateParams.cityId;

    $scope.heroList = [];

    function getHerosByCityId() {
        var url = "../../Api.ashx?sys:sno=Hero&sys:act=GetList&CityId=" + cityId;
        $http.get(url).success(function (data) {
            if (data.IsSuccess) {
                $scope.heroList = data.Data.Items;
            }
        })
    }
    getHerosByCityId();
})